package com.feng.mvc.dao;


import com.feng.mvc.bean.Employee;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class EmployeeDao {
    private static Map<Integer, Employee> employees = null;

    static {
        employees = new HashMap<Integer, Employee>();
        employees.put(1001,new Employee(1001,"AA","aa@163.com","女"));
        employees.put(1002,new Employee(1002,"BB","bb@163.com","女"));
        employees.put(1003,new Employee(1003,"CC","cc@163.com","男"));
        employees.put(1004,new Employee(1004,"DD","dd@163.com","女"));
        employees.put(1005,new Employee(1005,"EE","ee@163.com","男"));
    }
    private static Integer initId=1006;
    /*Sava 方法实现添加和修改*/
    public void save(Employee employee){
        if (employee.getId()==null)
            employee.setId(initId++);
        employees.put(employee.getId(),employee);
    }
    public Collection<Employee> getAll(){
        return employees.values();
    }

    public Employee getEmployeeById(Integer id){
        return employees.get(id);
    }

    public void deleteEmployee(Integer id){
        employees.remove(id);
    }
}
